import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 
 */

/**
 * @author Thai Huy Hoang_T123620
 * 
 */
public class cWE06_Prog01_T123620 extends JFrame {

	JButton btnS = new JButton("Send");
	JButton btnCancel = new JButton("Cancel");
	JTextField txtTo = new JTextField();
	JTextField txtCC = new JTextField();
	JTextField txtSJ = new JTextField();
	JTextArea txtE = new JTextArea();
	JTextArea txt = new JTextArea();
	JLabel lblTo = new JLabel("To: ");
	JLabel lblCC = new JLabel("CC: ");
	JLabel lblSJ = new JLabel("Subject: ");
	JLabel lblE = new JLabel("Email: ");

	public cWE06_Prog01_T123620() {
		this.setSize(350, 400);
		this.setTitle("MailEditor");
		this.setLayout(null);
		this.add(txtTo);
		this.add(txtCC);
		this.add(txtSJ);
		this.add(txtE);
		this.add(txt);
		this.add(lblTo);
		this.add(lblCC);
		this.add(lblSJ);
		this.add(lblE);
		this.add(btnS);
		this.add(btnCancel);

		btnS.setBounds(80, 300, 80, 20);
		btnCancel.setBounds(210, 300, 80, 20);
		lblTo.setBounds(10, 10, 250, 20);
		lblCC.setBounds(10, 40, 250, 20);
		lblSJ.setBounds(10, 70, 250, 20);
		lblE.setBounds(10, 100, 250, 20);
		txtTo.setBounds(80, 10, 250, 20);
		txtCC.setBounds(80, 40, 250, 20);
		txtSJ.setBounds(80, 70, 250, 20);
		txtE.setBounds(80, 100, 250, 150);
		txt.setBounds(80, 270, 250, 20);
		btnS.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String sTo = txtTo.getText().trim(), sSJ = txtSJ.getText()
						.trim(), sEmail = txtE.getText().trim();
				int x = sTo.length(), y = sSJ.length(), z = sEmail.length();
				if ((x == 0 || y == 0) || (x == 0 & y == 0)) {
					txt.append("ERROR");
				}
				if (z <= 20) {
					txt.append("EMAIL: INVALID INPUT");
				}

			}

		});
		btnCancel.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				System.exit(1);
			}
		});
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		cWE06_Prog01_T123620 mainWindow = new cWE06_Prog01_T123620();
		mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE);
		mainWindow.setVisible(true);

	}

}